using System;
using System.Globalization;

namespace Prometheus.Binding.ReadOnly.BaseConverters
{
    public class proAddTextConverter : proChainConverter
    {
        public AddTextMode Mode { get; set; }
        public string AddText { get; set; }
        public bool EmptyOnNull { get; set; }

        public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
                return EmptyOnNull ? string.Empty : AddText;

            string str = value.ToString();

            switch (Mode)
            {
                case AddTextMode.Prefix:
                    str = AddText + str;
                    break;
                case AddTextMode.Suffix:
                    str += AddText;
                    break;
            }
            return str;
        }

        public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException();
        }
    }

    public enum AddTextMode
    {
        Suffix = 0,
        Prefix = 1,
    }
}